#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef struct ListNode {
    int val;
    ListNode* next;
}ListNode;
typedef struct ListNode ListNode;
ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) {
    if (headA == NULL || headB == NULL)
    {
        return NULL;
    }
    ListNode* curA = headA;
    ListNode* curB = headB;
    //分别求两个链表的长度
    int lenA = 0;
    int lenB = 0;
    while (curA)
    {
        lenA++;
        curA = curA->next;
    }
    while (curB)
    {
        lenB++;
        curB = curB->next;
    }
    int step = abs(lenA - lenB);
    curA = headA;
    curB = headB;
    if (lenA >= lenB)
    {
        while (step--)
        {
            curA = curA->next;

        }
    }
    else
    {
        while (step--)
        {
            curB = curB->next;
        }
    }

    while (curA)
    {
        if (curA == curB)
        {
            return curA;
        }
        else
        {
            curA = curA->next;
            curB = curB->next;
        }
    }
    return NULL;
}



//ListNode* longlist=headA;
//ListNode* shortlist=headB;
//if(lenA<lenB)
//{
//    longlist=headB;
//    shortlist=headA;
//}
//while(step--)
//{
//    longlist=longlist->next;
//}
//while(longlist)
//{
//    if(longlist==shortlist)
//    return longlist;
//    longlist=longlist->next;
//    shortlist=shortlist->next;
//}
//return NULL;
//}